package mysqlxa;

import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.UUID;

/**
 * @author sjw
 * @description
 * @date 2019-09-22 下午4:05
 */
public class TimeZoneTest {
    public static void main(String[] args) {
        Connection c1 = null;
        System.out.println(TimeZone.getDefault());
        Statement s1 = null;
        //TimeZoneUtil.setTimeZone("UTC");
        try {
            c1 = ConnectionFactory.getConnection("192.168.10.66", "demo", "root", "123456", 3306);
            s1 = c1.createStatement();
            String ts=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            System.out.println(ts);
            boolean r1= s1.execute("insert into time (t,ts ) values ('"+ts+"','"+ts+"')");
            ResultSet resultSet= s1.executeQuery("select t,ts from time where id=2");
            resultSet.next();
            String date= resultSet.getString(1);
            System.out.println(date);
            System.out.println(resultSet.getString(2));
            resultSet =s1.executeQuery("select CURRENT_TIMESTAMP()");
            resultSet.next();
            System.out.println( resultSet.getDate(1));
            TimeZone.setDefault(TimeZone.getTimeZone("Europe/Paris"));
            Date d;
            Time t;
            resultSet= s1.executeQuery("select CURTIME()");// Time.class);
            resultSet.next();
            t=resultSet.getTime(1);
            resultSet= s1.executeQuery("select CURRENT_TIMESTAMP()");
            resultSet.next();
            d=resultSet.getDate(1);
            System.out.println(1);
        } catch (Exception e) {
            e.printStackTrace();


        } finally {
            if (c1 != null) {
                try {
                    c1.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
//
//    CREATE TABLE `time` (
//        `id` int(11) NOT NULL AUTO_INCREMENT,
//        `t` datetime DEFAULT NULL,
//        `ts` timestamp ,
//        `t1` datetime DEFAULT NULL on update  current timestamp ,
//        PRIMARY KEY (`id`)
//        );
//
//
//
//
//        CREATE TABLE `time` (
//        `id` int(11) NOT NULL AUTO_INCREMENT,
//        `t` datetime DEFAULT NULL,
//        `ts` timestamp ,
//        PRIMARY KEY (`id`)
//        );

